package com.wlw.admin.openeye

import android.content.Context
import android.support.v4.app.Fragment
import android.widget.Toast

fun Fragment.showToast(content: String): Toast {
    val toast = Toast.makeText(this.context, content, Toast.LENGTH_SHORT)
    toast.show()
    return toast
}

fun Context.showToast(content: String): Toast {
    val toast = Toast.makeText(this, content, Toast.LENGTH_SHORT)
    toast.show()
    return toast
}

fun durationFormat(duration: Long?): String {
    val minute = duration?.div(60)
    val second = duration?.rem(60)
    return if (minute!! <= 9) {
        if (second!! <= 9) "0 $minute' 0$second''"
        else "0$minute' $second''"
    } else {
        if (second!! <= 9) "$minute' 0$second''"
        else "$minute' $second''"
    }

}

fun dataFormat(total: Long): String {
    val result: String
    val speedReal: Int = (total / (1024)).toInt()
    result=if (speedReal<512) speedReal.toString()+"KB" else (Math.round(speedReal/1024.0*100)/100.0).toString()+"MB"
    return  result
}